import request from "@/utils/request.js";

// 分页查询
export const getUserPageService = (params) => {
    return request.get('/user', {params: params})
}

// 修改用户状态
export const updateUserStatusService = (params) => {
    return request.put('/user/status', null, {params})
}

// 删除用户
export const deleteUserService = (id) => {
    return request.delete(`/user/${id}`)
}

// 批量删除
export const deleteUsersService = (ids) => {
    return request.delete('/user/batch', {data: ids});
}

// 新增用户
export const addUserService = (params) => {
    return request.post('/user', params)
}

// 修改用户
export const updateUserService = (params) => {
    return request.put('/user', params)
}

// 导出用户数据
export const exportUserDataService = async (params) => {
    const response = await request.post('/user/export', params, {
        responseType: 'blob'
    });
    const url = window.URL.createObjectURL(new Blob([response.data]));
    const link = document.createElement('a');
    link.href = url;
    link.setAttribute('download', '用户信息表.xlsx');
    document.body.appendChild(link);
    link.click();
    link.remove();
    window.URL.revokeObjectURL(url);
};

// 修改用户密码
export const updateUserPasswordService = (params) => {
    return request.put('/user/password', params)
}

// 修改用户信息
export const updateUserProfileService = (params) => {
    return request.put('/user/profile', params)
}

// 获取用户信息
export const getUserProfileService = (userId) => {
    return request.get('/user/profile',
        {
            params: {userId}
        })
}
